<?php
// 文章管理
namespace app\bbs_admin\controller;

use think\Controller;
use think\Db;

class ArticleManagement extends Controller
{
  public function index()
  {
    return $this->ViewTheTistOfArticles();
  }
  public function ViewTheTistOfArticles() //查看文章列表
  {
    $head = bbs_admin_menu_hend();
    //获取所有文章分类
    $bbs_classification_main = Db::table('bbs_classification_main')
      ->where('start', 'eq', 0)
      ->select();
    foreach ($bbs_classification_main as $key => $value) {
      $bbs_classification_main[$key]['son'] = Db::table('bbs_classification_son')
        ->where([
          'son_class_start' => 0,
          'main_class_id' => $value['id']
        ])
        ->select();
      foreach ($bbs_classification_main[$key]['son'] as $key_son => $value_son) {
        $bbs_classification_main[$key]['son'][$key_son]['released_today'] =  Db::table('bbs_article')
          ->where([
            'class_id' => $value_son['id'],
            'release_data' => date('Y-m-d'),
          ])
          ->count();
        $bbs_classification_main[$key]['son'][$key_son]['All_theme_count'] =  Db::table('bbs_article')
          ->where([
            'class_id' => $value_son['id'],
          ])
          ->count();
      }
    }
    // dump($bbs_classification_main);
    return $this->fetch('ViewTheTistOfArticles', ['head' => $head, 'bbs_classification_main' => $bbs_classification_main]);
  }
  public function SelectArticlesList() //查看搜索到的文章列表
  {
    $articlelist_list_number = Db::table('bbs_settings')
      ->where(['id' => 1])
      ->field('articlelist_list_number')
      ->find()['articlelist_list_number'];
    /**
     * 按照时间查询
     *
     * @param int $articlelist_list_number 每页多少条
     * @param string $son_class_alias //那个分类下
     * @return json
     */
    function query_by_time($articlelist_list_number, $son_class_alias, $class_select_input) //按照时间查询
    {
      // 时间日期到时间戳
      $datetimepicker_start = input('datetimepicker_start', date('Y年m月d日H:i', 0));
      $datetimepicker_end = input('datetimepicker_end',  date('Y年m月d日H:i', time()));
      $datetimepicker_start = date_parse_from_format('Y年m月d日H:i', $datetimepicker_start);
      date_default_timezone_set("PRC");
      $datetimepicker_start = mktime($datetimepicker_start["hour"], $datetimepicker_start["minute"], 0, $datetimepicker_start["month"], $datetimepicker_start["day"], $datetimepicker_start["year"]);
      $datetimepicker_end = date_parse_from_format('Y年m月d日H:i', $datetimepicker_end);
      date_default_timezone_set("PRC");
      $datetimepicker_end = mktime($datetimepicker_end["hour"], $datetimepicker_end["minute"], 0, $datetimepicker_end["month"], $datetimepicker_end["day"], $datetimepicker_end["year"]);
      // $where['createdate'] = array(array('EGT', $datetimepicker_start) ,array('ELT', $datetimepicker_end));
      if ($datetimepicker_start == 943891200) {
        $datetimepicker_start = 0;
      }
      if ($datetimepicker_end == 943891200) {
        $datetimepicker_end = time();
      }
      // 时间日期到时间戳
      $where['bbs_article.time_stamp'] = [['EGT', $datetimepicker_start], ['ELT', $datetimepicker_end]];
      if ($son_class_alias) { // 判断有没有传入要查看的分类
        $data['class_alias'] = $son_class_alias; // 如果有 当前分类名字

        $son_class_id = Db::table('bbs_classification_son') //获取所有 传入分类的 id
          ->where(['son_class_alias' => $son_class_alias])
          ->field('id')
          ->find();
        $son_class_list['bbs_article.class_id'] = array('eq', $son_class_id['id']); //生成条件


        $data['bbs_article_count'] = Db::table('bbs_article') //统计传入的文章id的所有数量
          ->alias('bbs_article')
          ->where($son_class_list)
          ->where($class_select_input) //前台选择子分类
          ->where($where)
          ->count();
        //分页
        $_page = input('page', 1);
        if ($_page > ceil($data['bbs_article_count'] / $articlelist_list_number)) {
          $_page = ceil($data['bbs_article_count'] / $articlelist_list_number);
        }
        if ($_page < 1) {
          $_page = 1;
        }
        $data['page'] = getPageHtml($data['bbs_article_count'], $articlelist_list_number, $_page, $_GET); /* 生成分页html */
        //分页

        $data['bbs_article_list']  = Db::table('bbs_article')
          ->alias('bbs_article')
          ->join('bbs_classification_son bbs_classification_son', 'bbs_classification_son.id = bbs_article.class_id') //子分类
          ->join('bbs_classification_main bbs_classification_main', 'bbs_classification_main.id = bbs_classification_son.main_class_id') //主分类
          ->join('user user', 'user.id = bbs_article.user_id') //用户信息
          ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
          ->where($son_class_list)
          ->where($class_select_input) //前台选择子分类
          ->where($where)
          ->field(
            [
              'bbs_article.id',
              'bbs_article.title',
              'bbs_article.user_id',
              'bbs_article.time_stamp',
              'bbs_article.top',
              'bbs_article.top_time',
              'bbs_article.permission_to_read',
              'bbs_article.start',
              'bbs_classification_son.son_class_name as son_class_name', //子分类
              'bbs_classification_main.class_name as main_class_name', //主分类
              'user.user_name', //发布人用户名
              'user.email', //发布人用户名
              'bbs_jurisdiction_level.level_name', //阅读权限 - 名称
            ]
          )
          ->order('bbs_article.top desc,bbs_article.id desc')
          ->limit($_page * $articlelist_list_number - $articlelist_list_number, $articlelist_list_number)
          ->select();
      } else { //么有传入分类id
        $data['class_alias'] = '默认';
        $data['bbs_article_count'] = Db::table('bbs_article')
          ->alias('bbs_article')
          ->where($where)
          ->count();
        //分页
        $_page = input('page', 1);
        if ($_page > ceil($data['bbs_article_count'] / $articlelist_list_number)) {
          $_page = ceil($data['bbs_article_count'] / $articlelist_list_number);
        }
        if ($_page < 1) {
          $_page = 1;
        }
        $data['page'] = getPageHtml($data['bbs_article_count'], $articlelist_list_number, $_page, $_GET);
        //分页

        $data['bbs_article_list']  = Db::table('bbs_article')
          ->alias('bbs_article')
          ->join('bbs_classification_son bbs_classification_son', 'bbs_classification_son.id = bbs_article.class_id') //子分类
          ->join('bbs_classification_main bbs_classification_main', 'bbs_classification_main.id = bbs_classification_son.main_class_id') //主分类
          ->join('user user', 'user.id = bbs_article.user_id') //用户信息
          ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
          ->where($where)
          ->field(
            [
              'bbs_article.id',
              'bbs_article.title',
              'bbs_article.user_id',
              'bbs_article.time_stamp',
              'bbs_article.top',
              'bbs_article.top_time',
              'bbs_article.permission_to_read',
              'bbs_article.start',
              'bbs_classification_son.son_class_name as son_class_name', //子分类
              'bbs_classification_main.class_name as main_class_name', //主分类
              'user.user_name', //发布人用户名
              'user.email', //发布人用户名
              'bbs_jurisdiction_level.level_name', //阅读权限 - 名称
            ]
          )
          ->order('bbs_article.top desc,bbs_article.id desc')
          ->limit($_page * $articlelist_list_number - $articlelist_list_number, $articlelist_list_number)
          ->select();
      }

      $data['bbs_article_class_list'] = Db::table('bbs_classification_son')
        ->alias('bbs_classification_son')
        ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
        ->field(
          [
            'bbs_classification_son.son_class_name', //子分类
            'bbs_classification_son.son_class_alias', //子分类
          ]
        )
        ->distinct(true)
        ->select();
      array_unshift($data['bbs_article_class_list'], [
        'son_class_name' => '默认',
        'son_class_alias' => ''
      ]);

      return $data;
    }
    /**
     * 按照分类查询
     *
     * @param int $articlelist_list_number 每页多少条
     * @param string $son_class_alias //那个分类下
     * @return json
     */
    function query_by_class($articlelist_list_number, $son_class_alias, $class_select_input)
    {
      $class_name = explode(', ', $_GET['class_list_select'] . ', ');
      $bbs_classification_son_where['bbs_classification_son.son_class_name'] = array();
      foreach ($class_name as $key) {
        array_push($bbs_classification_son_where['bbs_classification_son.son_class_name'], ['eq', $key]);
      }
      if ($son_class_alias) {
        $data['class_alias'] = $son_class_alias;
        $son_class_id = Db::table('bbs_classification_son')
          ->where(['son_class_alias' => $son_class_alias])
          ->field('id')
          ->find();
        $son_class_list['bbs_article.class_id'] = array('eq', $son_class_id['id']);
        $data['bbs_article_count'] = $data['bbs_article_list'] = Db::table('bbs_classification_son')
          ->alias('bbs_classification_son')
          ->whereOR($bbs_classification_son_where)
          ->where($son_class_list)
          ->where($class_select_input) //前台选择子分类
          ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
          ->count();
        $_page = input('page', 1);
        if ($_page > ceil($data['bbs_article_count'] / $articlelist_list_number)) {
          $_page = ceil($data['bbs_article_count'] / $articlelist_list_number);
        }
        if ($_page < 1) {
          $_page = 1;
        }
        $data['page'] = getPageHtml($data['bbs_article_count'], $articlelist_list_number, $_page, $_GET);
        $data['bbs_article_list'] = Db::table('bbs_classification_son')
          ->alias('bbs_classification_son')
          ->whereOR($bbs_classification_son_where)
          ->where($son_class_list) //前台选择子分类
          ->where($class_select_input) //前台选择子分类
          ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
          ->join('bbs_classification_main bbs_classification_main', 'bbs_classification_main.id = bbs_classification_son.main_class_id') //主分类
          ->join('user user', 'user.id = bbs_article.user_id') //用户信息
          ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
          ->field(
            [
              'bbs_article.id',
              'bbs_article.title',
              'bbs_article.user_id',
              'bbs_article.time_stamp',
              'bbs_article.top',
              'bbs_article.top_time',
              'bbs_article.permission_to_read',
              'bbs_article.start',
              'bbs_classification_son.son_class_name as son_class_name', //子分类
              'bbs_classification_main.class_name as main_class_name', //主分类
              'user.user_name', //发布人用户名
              'user.email', //发布人用户名
              'bbs_jurisdiction_level.level_name', //阅读权限 - 名称
            ]
          )
          ->order('bbs_article.top desc,bbs_article.id desc')
          ->limit($_page * $articlelist_list_number - $articlelist_list_number, $articlelist_list_number)
          ->select();
      } else {
        $data['class_alias'] = '默认';
        $data['bbs_article_count'] = $data['bbs_article_list'] = Db::table('bbs_classification_son')
          ->alias('bbs_classification_son')
          ->whereOR($bbs_classification_son_where)
          ->where($class_select_input) //前台选择子分类
          ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
          ->count();
        $_page = input('page', 1);
        if ($_page > ceil($data['bbs_article_count'] / $articlelist_list_number)) {
          $_page = ceil($data['bbs_article_count'] / $articlelist_list_number);
        }
        if ($_page < 1) {
          $_page = 1;
        }
        $data['page'] = getPageHtml($data['bbs_article_count'], $articlelist_list_number, $_page, $_GET);
        $data['bbs_article_list'] = Db::table('bbs_classification_son')
          ->alias('bbs_classification_son')
          ->whereOR($bbs_classification_son_where)
          ->where($class_select_input) //前台选择子分类
          ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
          ->join('bbs_classification_main bbs_classification_main', 'bbs_classification_main.id = bbs_classification_son.main_class_id') //主分类
          ->join('user user', 'user.id = bbs_article.user_id') //用户信息
          ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
          ->field(
            [
              'bbs_article.id',
              'bbs_article.title',
              'bbs_article.user_id',
              'bbs_article.time_stamp',
              'bbs_article.top',
              'bbs_article.top_time',
              'bbs_article.permission_to_read',
              'bbs_article.start',
              'bbs_classification_son.son_class_name as son_class_name', //子分类
              'bbs_classification_main.class_name as main_class_name', //主分类
              'user.user_name', //发布人用户名
              'user.email', //发布人用户名
              'bbs_jurisdiction_level.level_name', //阅读权限 - 名称
            ]
          )
          ->order('bbs_article.top desc,bbs_article.id desc')
          ->limit($_page * $articlelist_list_number - $articlelist_list_number, $articlelist_list_number)
          ->select();
      }
      $data['bbs_article_class_list'] = Db::table('bbs_classification_son')
        ->alias('bbs_classification_son')
        ->whereOR($bbs_classification_son_where)
        ->join('bbs_article bbs_article', 'bbs_article.class_id = bbs_classification_son.id') //获取子分类下的所有信息
        ->field(
          [
            'bbs_classification_son.son_class_name', //子分类
            'bbs_classification_son.son_class_alias', //子分类
          ]
        )
        ->distinct(true)
        ->select();
      array_unshift($data['bbs_article_class_list'], [
        'son_class_name' => '默认',
        'son_class_alias' => ''
      ]);
      return $data;
    }
    $query_method = input('query_method', null); //查询方式
    $son_class_alias = input('son_class_alias', null); //查询方式
    $class_select_input = input('class_select_input', null); //查询方式
    $url = request()->domain() . url('bbs_admin/articlemanagement/SelectArticlesList') . '?' . http_build_query(array_merge($_GET)); //当前url
    if ($class_select_input) {
      $class_select_input_value['content'] = array('like', "%$class_select_input%");
    } else {
      $class_select_input_value['content'] = array('neq', "%d4a6wd4w6a$4d8aw64da6w46adw46class_select_input%");
    }
    switch ($query_method) {
      case 'query_by_time':
        $list = query_by_time($articlelist_list_number, $son_class_alias, $class_select_input_value);
        $head = bbs_admin_menu_hend();
        return $this->fetch('SelectArticlesList', ['head' => $head, 'list' => $list['bbs_article_list'], 'page' => $list['page'], 'bbs_article_class_list' => $list['bbs_article_class_list'], 'url' => $url, 'class_select_input' => $class_select_input, 'class_alias' => $list['class_alias']]);
        break;
      case 'query_by_class':
        $list = query_by_class($articlelist_list_number, $son_class_alias, $class_select_input_value);
        $head = bbs_admin_menu_hend();
        return $this->fetch('SelectArticlesList', ['head' => $head, 'list' => $list['bbs_article_list'], 'page' => $list['page'], 'bbs_article_class_list' => $list['bbs_article_class_list'], 'url' => $url, 'class_select_input' => $class_select_input, 'class_alias' => $list['class_alias']]);

        break;
      default:
        # code...
        break;
    }
  }
  public function article_select_index()
  {
    $head = bbs_admin_menu_hend();
    return $this->fetch('article_select_index', ['head' => $head]);
  }
  public function article_select_select()
  {
    $class_select_input = input('keyword');
    if ($class_select_input) {
      $class_select_input_value['title'] = array('like', "%$class_select_input%");
    }
    $list = Db::table('bbs_article')
      ->where($class_select_input_value)
      ->select();
    if ($list) {
      $this->success('success', null, $list);
    } else {
      $this->error($list);
    }
  }

  public function article_info_settings()
  {
    $id = input('id');
    if ($id) {
      $info =  Db::table('bbs_article')
        ->alias('bbs_article')
        ->where([
          'bbs_article.id' => $id
        ])
        ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
        ->join('bbs_classification_son bbs_classification_son', 'bbs_classification_son.id = bbs_article.class_id') //阅读权限
        ->field([
          'bbs_article.title',
          'bbs_article.content',
          'bbs_article.edit_or_not',
          'bbs_article.are_comments_allowed',
          'bbs_article.permission_to_read',
          'bbs_article.top',
          'bbs_article.class_id',
          'bbs_classification_son.son_class_name',
          'bbs_article.comment_email_notification',
          'user.id',
          'user.email',
          'user.user_name',
          'bbs_article.start',
        ])
        ->join('user user', 'user.id = bbs_article.user_id') //用户信息
        ->find();
      $bbs_jurisdiction_level = Db::table('bbs_jurisdiction_level')
        ->select();
      if ($info) {
        $info['top_time'] = date('Y年m月d日 H:i', 1609398000);
        //获取所有文章分类
        $bbs_classification_main = Db::table('bbs_classification_main')
          ->where('start', 'eq', 0)
          ->select();
        foreach ($bbs_classification_main as $key => $value) {
          $bbs_classification_main[$key]['son'] = Db::table('bbs_classification_son')
            ->where([
              'son_class_start' => 0,
              'main_class_id' => $value['id']
            ])
            ->select();
          foreach ($bbs_classification_main[$key]['son'] as $key_son => $value_son) {
            $bbs_classification_main[$key]['son'][$key_son]['released_today'] =  Db::table('bbs_article')
              ->where([
                'class_id' => $value_son['id'],
                'release_data' => date('Y-m-d'),
              ])
              ->count();
            $bbs_classification_main[$key]['son'][$key_son]['All_theme_count'] =  Db::table('bbs_article')
              ->where([
                'class_id' => $value_son['id'],
              ])
              ->count();
          }
        }
      } else {
        $this->error('没有这个文章');
      }
      $head = bbs_admin_menu_hend();
      return $this->fetch('article_info_settings', ['head' => $head, 'info' => $info, 'bbs_jurisdiction_level' => $bbs_jurisdiction_level, 'get_id' => $id, 'bbs_classification_main' => $bbs_classification_main]);
    } else {
      return $this->article_select_index();
    }
  }
  public function article_info_settings_save_essential_information() //文章详细设置保存基本信息页面
  {
    $datetimepicker_start = date_parse_from_format('Y年m月d日 H:i', $_POST['top_time']);
    date_default_timezone_set("PRC");
    $_POST['top_time'] = mktime($datetimepicker_start["hour"], $datetimepicker_start["minute"], 0, $datetimepicker_start["month"], $datetimepicker_start["day"], $datetimepicker_start["year"]);

    $id = input('id');
    $start = Db::table('bbs_article')
      ->where(['id' => $id])
      ->update($_POST);
    if ($start) {
      $this->success('success');
    } else {
      $this->error('error');
    }
  }
  public function article_info_settings_save_content() #保存内容
  {
    $id = input('id');
    $start = Db::table('bbs_article')
      ->where(['id' => $id])
      ->update($_POST);
    if ($start) {
      $this->success('success');
    } else {
      $this->error('error');
    }
  }
  public function extended_settings_super_settings_get_user_list() #获取用户列表
  {
    $user_list = Db::table('bbs_jurisdiction_level')
      ->select();
    foreach ($user_list as $key => $value) {
      $user_list[$key]['user_list'] = Db::table('user')
        ->where(['user_jurisdiction' => $value['jurisdiction_number']])
        ->select();
    }
    $this->success('success', null, ['list' => $user_list]);
  }
  public function article_info_settings_extended_settings_super_settings() #扩展设置-基本属性
  {
    $whether_to_notify_the_user = input('whether_to_notify_the_user');
    if ($whether_to_notify_the_user == "true") {
      $id = input('id');
      $class_id = input('class_id');
      $comment_email_notification = input('comment_email_notification');
      if ($comment_email_notification < 2 && $comment_email_notification > -1) { } else {
        $this->error('请重新选择是否通知用户');
        exit;
      }
      $bbs_article_info = Db::table('bbs_article')
        ->alias('bbs_article')
        ->where([
          'bbs_article.id' => $id
        ])
        ->join('bbs_classification_son bbs_classification_son', 'bbs_classification_son.id = bbs_article.class_id') //子分类
        ->find();
      if ($bbs_article_info['id'] == $class_id) {
        $class_html = "原分类 <a style='color:blue'> $bbs_article_info[son_class_name] </a> 新分类 <a style='color:red'> $bbs_article_info[son_class_name] </a> 未作修改";
      } else {
        $new_class_name = Db::table('bbs_classification_son')->where(['id' => $class_id])->find()['son_class_name'];
        if ($new_class_name) {
          $class_html = "原分类 <a style='color:blue'> $bbs_article_info[son_class_name] </a> 新分类 <a style='color:red'> $new_class_name </a> 已修改";
        } else {
          return $this->error('分类不存在');
          exit;
        }
      }
      if ($comment_email_notification == $bbs_article_info['comment_email_notification']) {
        if ($comment_email_notification == 0) {
          $email_html = "邮件通知 原状态 <a style='color:blue'> 已关闭 </a> 新状态 <a style='color:red'> 已关闭 </a> 未作修改";
        } else {
          $email_html = "邮件通知 原状态 <a style='color:blue'> 已开启 </a> 新状态 <a style='color:red'> 已开启 </a> 未作修改";
        }
      } else {
        if ($bbs_article_info['comment_email_notification'] == 1) {
          $los = '已开启';
        } else {
          $los = '未开启';
        }
        if ($comment_email_notification == 1) {
          $new = '已开启';
        } else {
          $new = '未开启';
        }
        $email_html = "邮件通知 原状态 <a style='color:blue'> $los </a> 新状态 <a style='color:red'> $new </a> 已修改";
      }

      $bbs_article_info = Db::table('bbs_article')
        ->where([
          'id' => $id
        ])
        ->update([
          'class_id' => $class_id,
          'comment_email_notification' => $comment_email_notification,
        ]);

      if ($bbs_article_info) {
        $html = "$class_html<br>$email_html";
        $html = article_info_settings_extended_settings_msg($html);
        D_Mail('文章信息已被管理员修改', $bbs_article_info['email'], $html);
        $this->success();
      } else {
        $this->error('可能未修改或修改失败');
      }
    } else {
      $id = input('id');
      $class_id = input('class_id');
      $comment_email_notification = input('comment_email_notification');
      $bbs_article_info = Db::table('bbs_article')
        ->where([
          'id' => $id
        ])
        ->update([
          'class_id' => $class_id,
          'comment_email_notification' => $comment_email_notification,
        ]);

      if ($bbs_article_info) {
        $this->success();
      } else {
        $this->error('可能未修改或修改失败');
      }
    }
  }
  public function article_info_settings_extended_settings_super_settings_extended_settings()
  {
    $id = input('id');
    $Current_User_Group = input('Current_User_Group');
    $Current_Select = input('Extended_Settings_Super_Settings_Current_Select'); //阅读权限
    $New_User_Group = input('New_User_Group');
    $Reason = input('Reason'); //变更理由
    $user_id = Db::table('user')
      ->where(['user_name' => $New_User_Group])
      ->field('id,user_name')
      ->find();

    $bbs_article = Db::table('bbs_article')
      ->where([
        'id' => $id,
        'user_id' => $Current_User_Group,
      ])
      ->find();

    switch ($Current_Select) {
      case '0':
        $article_start = '正常';
        break;
      case '1':
        $article_start = '用户删除';
        break;
      case '2':
        $article_start = '管理员删除';
        break;
      case '3':
        $article_start = '隐藏登陆显示';
        break;
      case '4':
        $article_start = '待审核';
        break;
      default:
        $this->error('状态设置错误');
        break;
    }
    switch ($bbs_article['start']) {
      case '0':
        $bbs_article['start'] = '正常';
        break;
      case '1':
        $bbs_article['start'] = '用户删除';
        break;
      case '2':
        $bbs_article['start'] = '管理员删除';
        break;
      case '3':
        $bbs_article['start'] = '隐藏登陆显示';
        break;
      case '4':
        $bbs_article['start'] = '待审核';
        break;
      default:
        $this->error('状态设置错误' . __LINE__);
        break;
    }

    if ($bbs_article) {
      $Current_User_Group_info = Db::table('user')
        ->where(['id' => $Current_User_Group])
        ->find();
      $start = Db::table('bbs_article')
        ->where([
          'id' => $id,
          'user_id' => $Current_User_Group,
        ])
        ->update([
          'user_id' => $user_id['id'],
          'start' => $Current_Select,
        ]);
      if ($start) {
        $html = article_info_settings_extended_settings_msg("您的文章$bbs_article[title]用户组已变更旧用户组$Current_User_Group_info[user_name] 新用户组 $user_id[user_name] <br> 文章状态 旧状态$bbs_article[start]  新状态 $article_start <br> 变更理由 <br> $Reason");
        D_Mail('文章信息已被管理员修改', $Current_User_Group_info['email'], $html);

        $this->success();
      } else {
        $this->error('可能是目标用户和原用户一致');
      }
    } else {
      $this->error('未找到原目标用户');
    }
  }
  public function management_to_be_audited()
  {
    $head = bbs_admin_menu_hend();
    $management_to_be_audited_list = Db::table('bbs_article')
      ->where(['bbs_article.start' => 4])
      ->alias('bbs_article')
      ->join('bbs_classification_son bbs_classification_son', 'bbs_classification_son.id = bbs_article.class_id') //子分类
      ->join('bbs_classification_main bbs_classification_main', 'bbs_classification_main.id = bbs_classification_son.main_class_id') //主分类
      ->join('user user', 'user.id = bbs_article.user_id') //用户信息
      ->join('bbs_jurisdiction_level bbs_jurisdiction_level', 'bbs_jurisdiction_level.jurisdiction_number = bbs_article.permission_to_read') //阅读权限
      ->field(
        [
          'bbs_article.id',
          'bbs_article.title',
          'bbs_article.user_id',
          'bbs_article.time_stamp',
          'bbs_article.top',
          'bbs_article.top_time',
          'bbs_article.permission_to_read',
          'bbs_article.start',
          'bbs_classification_son.son_class_name as son_class_name', //子分类
          'bbs_classification_main.class_name as main_class_name', //主分类
          'user.user_name', //发布人用户名
          'user.email', //发布人用户名
          'bbs_jurisdiction_level.level_name', //阅读权限 - 名称
        ]
      )
      ->select();
    return $this->fetch('ManagementToBeAudited', ['head' => $head, 'management_to_be_audited_list' => $management_to_be_audited_list]);
  }
}
